<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增借阅信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <script src="/static/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<form class="layui-form   layui-form-pane" action="">
    <!-- 用户ID -->
    <div class="layui-form-item">
        <label class="layui-form-label">用户ID</label>
        <div class="layui-input-block">
            <input type="text" name="user_id" value="" required lay-verify="required"
                   placeholder="请输入用户ID" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- 书籍ID -->
    <div class="layui-form-item">
        <label class="layui-form-label">书籍ID</label>
        <div class="layui-input-block">
            <input type="text" name="book_id" value="" required lay-verify="required"
                   placeholder="请输入书籍ID" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- 借书日期 -->
    <div class="layui-form-item">
        <label class="layui-form-label">借书日期</label>
        <div class="layui-input-block">
            <input type="text" name="borrow_date" value="" required
                   lay-verify="required"
                   placeholder="请输入借书时间" autocomplete="off" class="layui-input" id="borrow_date">
        </div>
    </div>
    <!-- 归还日期 -->
    <div class="layui-form-item">
        <label class="layui-form-label">归还日期</label>
        <div class="layui-input-block">
            <input type="text" name="return_date" value="" required
                   lay-verify="required" placeholder="请输入归还日期" autocomplete="off"
                   class="layui-input" id="return_date">
        </div>
    </div>
    <!-- 是否归还 -->
    <div class="layui-form-item">
        <label class="layui-form-label">是否归还</label>
        <div class="layui-input-block">
            <input type="text" name="is_returned" value="0" lay-verify="required" placeholder="是否归还:0未归还，1已归还"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- 是否逾期 -->
    <div class="layui-form-item">
        <label class="layui-form-label">是否逾期</label>
        <div class="layui-input-block">
            <input type="text" name="is_overdue" value="0" lay-verify="required"
                   placeholder="是否逾期:0未逾期，1已逾期" autocomplete="off" class="layui-input">
        </div>
    </div>
    <!-- 逾期天数 -->
    <div class="layui-form-item">
        <label class="layui-form-label">逾期天数</label>
        <div class="layui-input-block">
            <input type="text" name="overdue_days" value="0" lay-verify="required"
                   placeholder="请输入逾期天数" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>

<script>
    layui.use(['form', 'laydate'], function () {
        $ = layui.jquery;
        var form = layui.form
        var laydate = layui.laydate; // 日期选择
        // 执行借书日期实例
        laydate.render({
            elem: '#borrow_date' //指定元素
        });
        // 执行归还日期实例
        laydate.render({
            elem: '#return_date' //指定元素
        });
        // 执行实际归还日期实例
        laydate.render({
            elem: '#actual_return' //指定元素
        });
        //监听提交
        form.on('submit(formDemo)', function (data) {
            $.ajax({
                url: '/borrowInfoAdd',
                method: 'post',
                data: data.field, // JSON.stringify(data.field),
                dataType: 'json',
                success: function (data) {
                    if (data.code == "0") {
                        parent.layer.msg("新增成功", {
                            icon: 6,
                            time: 500
                        }, function () {
                            // 重新加载父页面
                            parent.location.reload();
                        });
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); // 操作父页面
                            parent.layer.close(index);
                        }, 500);

                    } else {
                        layer.msg("新增失败");
                    }
                }
            })
            return false;
        })
    })
</script>

</body>
</html>
